<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<title>完成付款</title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link href="../css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="../css/style.css" />
	<link rel="stylesheet" href="../css/iconfont.css" />
	<link rel="stylesheet" href="../css/wallet.css" />
</head>

<body>
	<div class="mui-content paymentcg_content">
		<div class="fukc_top">
			<div class="iconfont icon-weixin2" id='pay_tubiao'></div>
			<p>支付成功</p>
			<div class="fukc_pribox">¥<em id='pay_money'>0</em></div>
		</div>
		<div class="fukc_djh clearfix">
			<span class="left">单据号</span>
			<span class="right" id='sn'>XF2017060320001</span>
		</div>
		<div class="fukc_xq clearfix">
			<div class="left">付款详情</div>
			<div class="right">
				<p class="clearfix is_jif">
					<Span class="pleft" id='pay_model'>微信支付</Span>
					<span class="pright"><em id='pay_model_money'>0.00</em>元</span>
				</p>
				<p class="clearfix dixian" style="display: none;" >
					<Span class="pleft">鼓励金抵现</Span>
					<span class="pright"><em id='j_pay_score'>0.00</em></span>
				</p>
				<p class="clearfix zengsong" style="display: none;">
					<Span class="pleft">赠送鼓励金</Span>
					<span class="pright"><em id='s_pay_score'>0.00</em></span>
				</p>
			</div>
		</div>
		<div class="qitsj_lisbox">
			<div class="bt"><img src="../images/payment_ct.jpg"></div>
			<ul class="qitsj_lis" id='item_ul'>
				<!--<li class="clearfix">
					<div class="tjsj_img"><img src="../images/bgtu.jpg"></div>
					<div class="tjsj_info">
						<div class="tjsj_nam">
							<div class="name">英豪大酒店</div>
							<div class="iconfont icon-new"></div>
						</div>
						<div class="tjsj_jif">鼓励金最高可抵<em>100%</em></div>
						<div class="tjsj_dzbox clearfix">
							<div class="tjsj_dz">北湖区，南岭大道辅路</div>
							<div class="tjsj_jul">3.295km</div>
						</div>
					</div>
				</li>-->
			</ul>
		</div>
		<div class="mask">
			<div class="fuk_bdsj">
				<p class="bt">绑定手机号</p>
				<p><img src="../images/bac_bdsj.jpg"></p>
				<p class="tip">绑定手机号，让您的账户更加安全</p>
				<p class="number"><input type="number" name="" id="member_mobile" value="" placeholder="请输入您的手机号" /></p>
				<div class="yzm clearfix">
					<input type="text" name="" id="yzm" value="" placeholder="请输入验证码" />
					<button type="button" class="fuk_yzmbtn" id="send_code">获取验证码</button>
				</div>
				<p><button type="button" class="fukc_btn" id='bd_mobile'>确定</button></p>
			</div>			
		</div>
	</div>
	<div id="allmap"></div>
	<script src="../js/mui.min.js"></script>
	<script type="text/javascript">
		mui.init()
	</script>
</body>
</html>
<script src="../js/mui.min.js"></script>
<script src="../js/zepto.min.js"></script>
<script type="text/javascript" src="../js/date.js"></script>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/layer/layer.min.js"></script>
<script type="text/javascript" src="../js/app.js"></script>
<script>
	$(function(){
		getAddress();
		var axis =JSON.parse(localStorage.getItem('axis'));
		var longitude = 113.022014;
		var latitude = 25.779124;
		
		if(axis){
			longitude = axis.longitude;
			latitude = axis.latitude;
		}
		//获取付款信息
		$.ajax({
			//type: 'post',
			url: APP.api_url + 'wallet/pay_info',
			data: {
					sn			: getUrlParam('sn'),
					longitude	: longitude,
					latitude	: latitude
			},
			success: function(data) {
				if(data.code == 200){
					var paylog = data.data.pay_log;
					var user_info = data.data.user_info;
					if(paylog){
						//更新用户信息
						localStorage.setItem('member', JSON.stringify(user_info));
						var member =JSON.parse(localStorage.getItem('member'));
						if(!member['mobile'] || member['mobile'].length <2){
							$('.mask').show();
						}
						$("#pay_money").text(paylog.score); 		//实付金额
						$("#pay_model_money").text(paylog.price);	//应付金额
						//是否送鼓励金显示uesr_payee 用户，ads_order
						if(paylog.type=='uesr_payee'){	//用户收款
							$("#pay_money").text(paylog.price);
						}else{	//商家收款
							if(parseFloat(paylog.price) ==parseFloat(paylog.score)){	//收付款金额是否相等
								//收款商家信息
								var shou_agent = data.data.shou_agent;
								//检查商家是否开启鼓励金营销
								if(shou_agent && shou_agent['is_union_score'] == 1){
									//计算鼓励金金额
									if(paylog.price >=1){
										var s_pay_score = paylog.price * shou_agent['ad_score']/100;
										$("#s_pay_score").text(s_pay_score);
									}
									$(".zengsong").show();
									
								}
							}else{
								$(".dixian").show();
								$("#j_pay_score").text((parseFloat((paylog.score*100) -(paylog.price*100))/100).toFixed(2));
							}
						}
						
						$("#sn").text(paylog.sn)
						
						var pay_type = paylog.pay_type;
						if(pay_type == 2){	
							$("#pay_model").text("微信付款");
							//删除样式
							$('#pay_tubiao').removeClass("icon-zhifubao1");
							//添加样式
							$('#pay_tubiao').addClass("icon-weixin2");
						}else if(pay_type == 3){
							$("#pay_model").text("支付宝付款");
							//删除样式
							$('#pay_tubiao').removeClass("icon-weixin2");
							//添加样式
							$('#pay_tubiao').addClass("icon-zhifubao1");
						}else if(pay_type == 5){	//鼓励金付款
							$("#pay_money").text(paylog.price);
							$('.is_jif').hide();
							$("#j_pay_score").text((parseFloat(paylog.price)).toFixed(2));
						}
						agent_list = data.data.agent_list;
						var item_htm="";
						for(var i=0;i<agent_list.length;i++){
							//图片地址
							var img = user_tupian(agent_list[i].store_logo,'/images/logo-ma.jpg');
							var jl = agent_list[i].juli;
							var unit = "m";
							if(jl>1000){
								jl = jl/1000;
								unit = "km";
							}
							item_htm =  "<li class='clearfix'><div class='tjsj_img' onclick ='goto_shop("+agent_list[i].agent_id+")'>"+
										"<img src='"+img+"'></div>"+
										"<div class='tjsj_info'><div class='tjsj_nam'>"+
										"<div class='name'>"+agent_list[i].store_name+"</div>"+
										"<div class='iconfont icon-new'></div></div>"+
										"<div class='tjsj_jif'>鼓励金最高可抵<em>"+agent_list[i].ad_score+"%</em></div>"+
										"<div class='tjsj_dzbox clearfix'>"+
										"<div class='tjsj_dz'>"+agent_list[i].address+"</div>"+
										"<div class='tjsj_jul'>"+jl+unit+"</div>"+
										"</div></div></li>";
							$("#item_ul").append(item_htm);
						}
					}
				}
			}
		});
	})
	function goto_shop(stor_id){
			location.href = '../shop.html?store_id='+stor_id;
		}
	
	
	//true就是可以发送
	var onoff = true;
	var send_code = $('#send_code');
	var btn = $("#bd_mobile");
	//发送验证码
	$('.fuk_yzmbtn').click(function() {
		//false就不能发送
		if(!onoff) {
			return;
		}
		onoff = false;
		//点击玩按钮干什么?
		//发验证码? 
		// 1-给谁发? 手机号码
		var phone = $("#member_mobile").val();
		if(phone == '') {
			layer.msg('手机号码不能为空');
			onoff = true;
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
		$.ajax({
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: APP.api_url + 'System/get_login_sms_',
			//请求的过程中传递过去的参数 json
			data: {
				mobile: phone
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg);
				var num = 60;
				var timer = setInterval(function() {
					num--;
					if(num == 0) {
						send_code.html('发送验证码');
						//send_code.innerHTML = '发送验证码';
						//定时器停了
						clearInterval(timer);
						onoff = true;
					} else {
						send_code.html(num + 'S');
					}
				}, 1000); // 1000 毫秒==1秒
			}
		})

	});
	
	
	$("#bd_mobile").click(function(){
		var phone = $("#member_mobile").val();
		var input_code = $("#yzm").val();
		if(phone == '') {
			layer.msg('手机号码不能为空');
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
		if(input_code.trim() == '') {
			layer.msg('验证码不能为空');
			return;
		}
		btn.disabled = true;
		setTimeout(function() {
			btn.disabled = false;
		}, 1500);
		//写入数据库
		var a = getUid();
		$.ajax({
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: APP.api_url + 'Member/my_mobile',
			//请求的过程中传递过去的参数 json
			data: {
				mobile: phone,
				verifycode: input_code,
				uid:getUid(),
				token:get_token()
			},
			type: "post",
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg, {time: 2000}, function() {
					location.reload();
				});
			}
		})
	});
</script>